﻿@page "/Admin/Machines"
@attribute [Authorize]
@attribute [TabItemOption(Text ="服务监控",Icon ="fa fa-th")]
@inherits BasePage
@inject ISysMachineService SysMachineService

<Row ItemsPerRow="ItemsPerRow.Two">
    <Card>
        <CardHeader>系统信息</CardHeader>
        <CardBody>
            <table class="table">
                <tbody>
                    <tr><td>主机名称：</td><td>@_baseInfo?.HostName</td></tr>
                    <tr><td>操作系统：</td><td>@_baseInfo?.SystemOs</td></tr>
                    <tr><td>系统架构：</td><td>@_baseInfo?.OsArchitecture</td></tr>
                    <tr><td>运行框架：</td><td>@_baseInfo?.FrameworkDescription</td></tr>
                    <tr><td>CPU核数：</td><td>@_baseInfo?.ProcessorCount</td></tr>
                </tbody>
            </table>
        </CardBody>
    </Card>
    <Card>
        <CardHeader>网络信息</CardHeader>
        <CardBody>
            <table class="table">
                <tbody>
                    <tr><td>外网信息：</td><td>@_baseInfo?.WanIp</td></tr>
                    <tr><td>IPv4地址：</td><td>@_baseInfo?.LanIp</td></tr>
                    <tr><td>网卡MAC：</td><td>@_baseInfo?.IpMac</td></tr>
                    <tr><td>流量统计：</td><td>@_baseInfo?.SendAndReceived</td></tr>
                    <tr><td>网络速度：</td><td>@_baseInfo?.NetworkSpeed</td></tr>
                </tbody>
            </table>
        </CardBody>
    </Card>
</Row>

<Row ItemsPerRow="ItemsPerRow.One">  
    <Card class="mt-4" >
        <CardHeader>其他信息</CardHeader>
        <CardBody>
            <table class="table">
                <tbody>
                    <tr><td>运行时间：</td><td>@_useInfo?.RunTime</td><td>CPU使用率：</td><td>@_useInfo?.CpuRate</td></tr>
                    <tr><td>系统内存：</td><td>@_useInfo?.TotalRam</td><td>内存使用率：</td><td>@_useInfo?.RamRate</td></tr>
                </tbody>
            </table>
        </CardBody>
    </Card>
</Row>

@code{
    private MachineUseOutput? _useInfo = new();
    private MachineBaseOutput? _baseInfo = new();
    //private MachineNetOutput? _netInfo = new();

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (firstRender)
        {
            _useInfo = await SysMachineService.UseAsync();
            _baseInfo = await SysMachineService.BaseAsync();
            //_netInfo = await SysMachineService.NetworkAsync();
            StateHasChanged();
        }
    }
}

